package com.boot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boot.entity.User;
import com.boot.mapper.UserMapper;
import com.boot.service.IUserService;
import org.springframework.stereotype.Service;

/**
 * @author bbyh
 * @since 2024-04-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public User getUserByUsernameAndPassword(User userVo) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUsername, userVo.getUsername()).eq(User::getPassword, userVo.getPassword());
        return getOne(wrapper);
    }

    @Override
    public Integer getUserIdByUsername(String username) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUsername, username);
        User user = getOne(wrapper);
        if (user == null) {
            throw new RuntimeException("上传用户身份不存在，文件上传失败");
        }
        return user.getUserId();
    }
}
